<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>User Registration</title>
  <script src="static/jquery-3.6.0.min.js"></script>
  <script>
    $(document).ready(function() {
      $('#username').on('blur', function() {
        var username = $(this).val();
        $.ajax({
          type: 'POST',
          url: '/username',  // 后端检查用户名是否存在的路由
          data: { username: username },
          success: function(response) {
            if (response.exists) {
              $('#usernameError').text('Username already exists');
            } else {
              $('#usernameError').text('');
            }
          }
        });
      });
    });
  </script>
  <style>
    body {
      font-family: Arial, sans-serif;
      background-color: #f4f4f4;
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100vh;
      margin: 0;
    }
    h1 {
      text-align: center;
      color: #4CAF50;
      margin-bottom: 20px;
    }
    form {
      background-color: #fff;
      padding: 40px;
      border-radius: 5px;
      box-shadow: 0px 0px 10px 0px #000000;
      width: 300px;
      text-align: left;
    }
    input[type="text"], input[type="password"] {
      width: 100%;
      padding: 10px;
      margin: 8px 0;
      border: 1px solid #ccc;
      border-radius: 4px;
      box-sizing: border-box;
    }
    button[type="submit"] {
      width: 100%;
      padding: 10px;
      margin: 8px 0;
      border: none;
      border-radius: 4px;
      cursor: pointer;
      background-color: #4CAF50;
      color: white;
      transition: background-color 0.3s ease;
    }
    button[type="submit"]:hover {
      background-color: #45a049;
    }
    a {
      text-decoration: none;
      display: block;
      margin-top: 20px;
      text-align: center;
      color: #4CAF50;
    }
    a:hover {
      text-decoration: underline;
    }
  </style>
</head>
<body>
  <center>
  <h1>注册用户</h1>
  <form action="/register" method="post">
    <div>
      <label for="username">用户名:</label>
    <input type="text" id="username" name="username" required>
    </div>
    <span id="usernameError" style="color: red;"></span><br>
    <div>
    <label for="password">密码:</label>
    <input type="password" name="password" required><br>
    </div>
    <button type="submit">注册</button>
  </form>
  <p>已经注册？<a href="/login">点击这里返回登录</a></p>
  </center>
</body>
</html>

